
Imports System
Imports System.Collections
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Web
Imports System.Web.SessionState
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls
Imports System.IO
Imports System.Text
Imports _2bMatesSite.BO

Namespace _2bMatesSite
	''' <summary>
	''' Summary description for user_profile.
	''' </summary>
	Public Partial Class user_profile
		Inherits BaseWebPage
		Private MIN_YEAR As Integer = Constants.MIN_YEAR
		Private MAX_YEAR As Integer = Constants.MAX_YEAR
		Protected lblShowOnline As System.Web.UI.WebControls.Label
		Protected rbYes As System.Web.UI.WebControls.RadioButton
		Protected rbNo As System.Web.UI.WebControls.RadioButton
		Protected rvTxtFirstName As System.Web.UI.WebControls.RequiredFieldValidator
		Protected litFormTitle As System.Web.UI.WebControls.Literal
		Protected divPrivacyVisibility As String = ""
		Protected textarea_max_chars As String = ""
		Protected htPageConstants As New Hashtable()

		Protected divVisibility As String

		Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)

			' Auto login from an external link
			'AutoLogin( Request );

			' this.pageTemplate.PageTitle = PageTitles.USER_PROFILE_PAGE;
			Session.LCID = 1033
			Dim user As User = Me.LoggedUser
			If user = Nothing Then
				Common.Utils.RedirectToLoginPage(Page)
			End If

			Me.initPageTitles(Constants.USER_PROFILE, "", Form1, Nothing, htPageConstants)
			Me.initAdvertisements(Form1, Nothing)

			' Put user code to initialize the page here
			Dim i As Integer
			textarea_max_chars = Constants.TEXT_AREA_DEFAULT_MAX_CHARS.ToString()

			If Request.Params("action") = Constants.PROFILE_CHANGES_SUBMITTED.ToString() Then
				lblChangesSubmitted.Visible = True
			End If

			If Not Me.IsPostBack Then
				i = 1
				While i <= 31
					ddlDay.Items.Add(i.ToString())
					System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1)
				End While
				' Fill in Months
				Dim months As String() = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", _
					"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}
				i = 1
				While i <= 12
					ddlMonth.Items.Add(months(i - 1))
					ddlMonth.Items.FindByText(months(i - 1)).Value = i.ToString()
					System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1)
				End While
				' Fill in Years
				i = MAX_YEAR
				While i >= MIN_YEAR
					ddlYear.Items.Add(i.ToString())
					System.Math.Max(System.Threading.Interlocked.Decrement(i),i + 1)
				End While

				'ddlCountry.Items.Add("----Choose Country----");
				'ddlCountry.Items.FindByText("----Choose Country----").Value = "-1";
				Dim countriesCount As Integer = Constants.COUNTRIES.List.Count
				Dim tempCountry As Countries.Country

				i = 0
				While i < countriesCount
					tempCountry = DirectCast(Constants.COUNTRIES.List(i), Countries.Country)
					ddlCountry.Items.Add(tempCountry.Name)
					ddlCountry.Items.FindByText(tempCountry.Name).Value = tempCountry.ID.ToString()
					System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1)
				End While


				txtFirstName.Text = user.Name
				txtLastName.Text = user.LastName

				Dim genderValue As Integer = user.Gender
				Select Case genderValue
					Case 1
						rbMale.Checked = True
						Exit Select
					Case 2
						rbFemale.Checked = True
						Exit Select
				End Select
				txtHiddenGender.Text = genderValue.ToString()
				Dim birthDay As DateTime = user.BirthDay
				Dim day As String = birthDay.Day.ToString()
				Dim month As String = birthDay.Month.ToString()
				Dim year As String = birthDay.Year.ToString()
				ddlDay.Items.FindByValue(day).Selected = True
				ddlMonth.Items.FindByValue(month).Selected = True
				ddlYear.Items.FindByValue(year).Selected = True
				txtDateOfBirth.Text = month + "/" + day + "/" + year

				chkFor1.Checked = user.MatesSR
				chkFor2.Checked = user.MatesPen
				chkFor3.Checked = user.MatesFriends
				chkFor4.Checked = user.MatesDating
				chkFor5.Checked = user.MatesAP
				chkFor6.Checked = user.MatesJHO

				If Not user.MatesSR AndAlso Not user.MatesPen AndAlso Not user.MatesFriends AndAlso Not user.MatesDating AndAlso Not user.MatesAP AndAlso Not user.MatesJHO Then
					' by default those two are checked	
					chkFor3.Checked = True
					chkFor6.Checked = True
				End If

				Dim genderPrefValue As Integer = user.GenderPreference
				Select Case genderPrefValue
					Case 1
						rbMen.Checked = True
						Exit Select
					Case 2
						rbWomen.Checked = True
						Exit Select
					Case Else
						rbMenAndWomen.Checked = True
						Exit Select
				End Select
				txtHiddenToBeMatesWith.Text = genderPrefValue.ToString()

				Dim maritalStatus As Integer = user.MaritalStatus
				Select Case maritalStatus
					Case 1
						rbSDS.Checked = True
						Exit Select
					Case 2
						rbInRelationship.Checked = True
						Exit Select
					Case 3
						rbOpenRelationship.Checked = True
						Exit Select
					Case 4
						rbMarried.Checked = True
						Exit Select
					Case 5
						rbOpenMarriage.Checked = True
						Exit Select
				End Select

				txtReferrer.Visible = False
				lblReferrerExplain.Visible = False
				cvReferrer.Visible = False
				revTxtReferrer.Visible = False

				Dim referrer As BO.User = BO.Users.GetUserByID(DirectCast(user.RefererID, Integer))
				If referrer <> Nothing Then
					lblReferrerValue.Text = referrer.Email
					lblReferrerValue.Visible = True
				Else
					lblReferrer.Visible = False
				End If

				txtAboutMe.Text = user.AboutMe
				txtAboutMe.Attributes.Add("onKeyDown", Constants.ON_KEY_DOWN_SCRIPT.Replace(Constants.TEXT_AREA_MAX_CHARS_TAG, Constants.TEXT_AREA_ABOUT_ME_MAX_CHARS.ToString()))
				txtAboutMe.Attributes.Add("onKeyUp", Constants.ON_KEY_UP_SCRIPT.Replace(Constants.TEXT_AREA_MAX_CHARS_TAG, Constants.TEXT_AREA_ABOUT_ME_MAX_CHARS.ToString()))

				txtLookingFor.Text = user.LookingFor
				txtLookingFor.Attributes.Add("onKeyDown", Constants.ON_KEY_DOWN_SCRIPT.Replace(Constants.TEXT_AREA_MAX_CHARS_TAG, Constants.TEXT_AREA_LOOKING_FOR_MAX_CHARS.ToString()))
				txtLookingFor.Attributes.Add("onKeyUp", Constants.ON_KEY_UP_SCRIPT.Replace(Constants.TEXT_AREA_MAX_CHARS_TAG, Constants.TEXT_AREA_LOOKING_FOR_MAX_CHARS.ToString()))
				If user.CountryID > 0 Then
					ddlCountry.ClearSelection()
					ddlCountry.Items.FindByValue(user.CountryID.ToString()).Selected = True
				End If
				txtCity.Text = user.City

				txtZip.Text = user.ZipCode

				txtPlaceOfBirth.Text = user.PlaceOfBirth

				txtInterests.Text = user.Interests
				txtInterests.Attributes.Add("onKeyDown", Constants.ON_KEY_DOWN_SCRIPT.Replace(Constants.TEXT_AREA_MAX_CHARS_TAG, Constants.TEXT_AREA_LONG_MAX_CHARS.ToString()))
				txtInterests.Attributes.Add("onKeyUp", Constants.ON_KEY_UP_SCRIPT.Replace(Constants.TEXT_AREA_MAX_CHARS_TAG, Constants.TEXT_AREA_LONG_MAX_CHARS.ToString()))

				txtOccupation.Text = user.Occupation
				txtOccupation.Attributes.Add("onKeyDown", Constants.ON_KEY_DOWN_SCRIPT.Replace(Constants.TEXT_AREA_MAX_CHARS_TAG, Constants.TEXT_AREA_OCCUPATION_MAX_CHARS.ToString()))
				txtOccupation.Attributes.Add("onKeyUp", Constants.ON_KEY_UP_SCRIPT.Replace(Constants.TEXT_AREA_MAX_CHARS_TAG, Constants.TEXT_AREA_OCCUPATION_MAX_CHARS.ToString()))

				txtAffiliations.Text = user.Affiliations
				txtAffiliations.Attributes.Add("onKeyDown", Constants.ON_KEY_DOWN_SCRIPT.Replace(Constants.TEXT_AREA_MAX_CHARS_TAG, Constants.TEXT_AREA_AFFILIATIONS_MAX_CHARS.ToString()))
				txtAffiliations.Attributes.Add("onKeyUp", Constants.ON_KEY_UP_SCRIPT.Replace(Constants.TEXT_AREA_MAX_CHARS_TAG, Constants.TEXT_AREA_AFFILIATIONS_MAX_CHARS.ToString()))

				txtCompanies.Text = user.Companies
				txtCompanies.Attributes.Add("onKeyDown", Constants.ON_KEY_DOWN_SCRIPT.Replace(Constants.TEXT_AREA_MAX_CHARS_TAG, Constants.TEXT_AREA_COMPANIES_MAX_CHARS.ToString()))
				txtCompanies.Attributes.Add("onKeyUp", Constants.ON_KEY_UP_SCRIPT.Replace(Constants.TEXT_AREA_MAX_CHARS_TAG, Constants.TEXT_AREA_COMPANIES_MAX_CHARS.ToString()))

				txtSchools.Text = user.Schools
				txtSchools.Attributes.Add("onKeyDown", Constants.ON_KEY_DOWN_SCRIPT.Replace(Constants.TEXT_AREA_MAX_CHARS_TAG, Constants.TEXT_AREA_SCHOOLS_MAX_CHARS.ToString()))
				txtSchools.Attributes.Add("onKeyUp", Constants.ON_KEY_UP_SCRIPT.Replace(Constants.TEXT_AREA_MAX_CHARS_TAG, Constants.TEXT_AREA_SCHOOLS_MAX_CHARS.ToString()))
				'
'				if(user.SongURL1 != null && user.SongURL1 != "")
'					txtFavClipSongURL1.Text = user.SongURL1;
'				if(user.SongURLName1 != null && user.SongURLName1 != "")
'					txtFavClipSongName1.Text = user.SongURLName1;
'				if(user.SongURL2 != null && user.SongURL2 != "")
'					txtFavClipSongURL2.Text = user.SongURL2;
'				if(user.SongURLName2 != null && user.SongURLName2 != "")
'					txtFavClipSongName2.Text = user.SongURLName2;
'				if(user.SongURL3 != null && user.SongURL3 != "")
'					txtFavClipSongURL3.Text = user.SongURL3;
'				if(user.SongURLName3 != null && user.SongURLName3 != "")
'					txtFavClipSongName3.Text = user.SongURLName3;
'				

				If user.ImageURL <> Nothing AndAlso user.ImageURL <> "" Then
					txtFavImage.Text = user.ImageURL
				End If
				If user.ImageURLName <> Nothing AndAlso user.ImageURLName <> "" Then
					txtFavImageName.Text = user.ImageURLName
				End If

				txtFavMusic.Text = user.Music
				txtFavMusic.Attributes.Add("onKeyDown", Constants.ON_KEY_DOWN_SCRIPT.Replace(Constants.TEXT_AREA_MAX_CHARS_TAG, Constants.TEXT_AREA_LONG_MAX_CHARS.ToString()))
				txtFavMusic.Attributes.Add("onKeyUp", Constants.ON_KEY_UP_SCRIPT.Replace(Constants.TEXT_AREA_MAX_CHARS_TAG, Constants.TEXT_AREA_LONG_MAX_CHARS.ToString()))

				txtFavBooks.Text = user.Books
				txtFavBooks.Attributes.Add("onKeyDown", Constants.ON_KEY_DOWN_SCRIPT.Replace(Constants.TEXT_AREA_MAX_CHARS_TAG, Constants.TEXT_AREA_LONG_MAX_CHARS.ToString()))
				txtFavBooks.Attributes.Add("onKeyUp", Constants.ON_KEY_UP_SCRIPT.Replace(Constants.TEXT_AREA_MAX_CHARS_TAG, Constants.TEXT_AREA_LONG_MAX_CHARS.ToString()))

				txtFavTVShows.Text = user.TV
				txtFavTVShows.Attributes.Add("onKeyDown", Constants.ON_KEY_DOWN_SCRIPT.Replace(Constants.TEXT_AREA_MAX_CHARS_TAG, Constants.TEXT_AREA_LONG_MAX_CHARS.ToString()))
				txtFavTVShows.Attributes.Add("onKeyUp", Constants.ON_KEY_UP_SCRIPT.Replace(Constants.TEXT_AREA_MAX_CHARS_TAG, Constants.TEXT_AREA_LONG_MAX_CHARS.ToString()))

				txtFavMovies.Text = user.Movies
				txtFavMovies.Attributes.Add("onKeyDown", Constants.ON_KEY_DOWN_SCRIPT.Replace(Constants.TEXT_AREA_MAX_CHARS_TAG, Constants.TEXT_AREA_LONG_MAX_CHARS.ToString()))

				txtFavMovies.Attributes.Add("onKeyUp", Constants.ON_KEY_UP_SCRIPT.Replace(Constants.TEXT_AREA_MAX_CHARS_TAG, Constants.TEXT_AREA_LONG_MAX_CHARS.ToString()))
			End If
			divPrivacyVisibility = "display: none"
			btnSignMeUp.Text = "Update Profile"
			btnSignMeUp.Width = 150

			litTitle.Text = "Edit Profile " + user.Name + " ( " + user.Email + " )"
			litRightLinks.Text = "<a href='" + Constants.MEMBERS + "' class=""white_link"">View My Profile</a>"

			litRightLinks.Visible = True

			lblReferrer.Visible = False
			txtReferrer.Visible = False
			lblReferrerValue.Visible = False
			cvReferrer.Visible = False
			revTxtReferrer.Visible = False

		End Sub

		#region Web Form Designer generated code
		Protected Overloads Overrides Sub OnInit(ByVal e As EventArgs)
			'
			' CODEGEN: This call is required by the ASP.NET Web Form Designer.
			'
			InitializeComponent()
			MyBase.OnInit(e)
		End Sub

		''' <summary>
		''' Required method for Designer support - do not modify
		''' the contents of this method with the code editor.
		''' </summary>
		Private Sub InitializeComponent()
			AddHandler Me.cvHtmlInCity.ServerValidate, AddressOf Me.cvHtmlInCity_ServerValidate
			AddHandler Me.cvHtmlInZip.ServerValidate, AddressOf Me.cvHtmlInZip_ServerValidate
			AddHandler Me.cvHtmlInPlaceOfBirth.ServerValidate, AddressOf Me.cvHtmlInPlaceOfBirth_ServerValidate
			AddHandler Me.cvHtmlInFirstName.ServerValidate, AddressOf Me.cvHtmlInFirstName_ServerValidate
			AddHandler Me.cvHtmlInLastName.ServerValidate, AddressOf Me.cvHtmlInLastName_ServerValidate
			AddHandler Me.cvZip.ServerValidate, AddressOf Me.cvZip_ServerValidate
			AddHandler Me.cvReferrer.ServerValidate, AddressOf Me.cvReferrer_ServerValidate

		End Sub
#End Region

		Protected Sub validateList(ByVal sender As Object, ByVal args As ServerValidateEventArgs)
			args.IsValid = True
			If args.Value = "0" Then
				args.IsValid = False
			End If
		End Sub

		Protected Sub validateDate(ByVal sender As Object, ByVal args As ServerValidateEventArgs)
			Dim day As String = ddlDay.SelectedItem.Value
			Dim month As String = ddlMonth.SelectedItem.Value
			Dim year As String = ddlYear.SelectedItem.Value
			If day <> "0" OrElse month <> "0" OrElse year <> "0" Then
				If Not isDate(day, month, year) Then
					'"Please, choose correct date of birth");
					args.IsValid = False
				Else
					args.IsValid = True
				End If
			End If
		End Sub

		Protected Sub validateReferer(ByVal sender As Object, ByVal args As ServerValidateEventArgs)
			Dim refererEmail As String = txtReferrer.Text
			refererEmail.Trim()

			If refererEmail.Length > 0 Then
				Dim referer As BO.User = BO.Users.GetUserByEmail(refererEmail)
				args.IsValid = referer <> Nothing
			Else
				args.IsValid = True
			End If
		End Sub

		Protected Function isDate(ByVal strDay As String, ByVal strMonth As String, ByVal strYear As String) As Boolean
			Dim validDate As Boolean = False

			Try
				' try creating the date
				New DateTime(Convert.ToInt32(strYear), Convert.ToInt32(strMonth), Convert.ToInt32(strDay))
				validDate = True
			Catch
			End Try

			Return validDate
		End Function

		Protected Sub GenerateDate(ByVal sender As Object, ByVal args As ServerValidateEventArgs)
			Dim day As String = ddlDay.SelectedItem.Value
			Dim month As String = ddlMonth.SelectedItem.Value
			Dim year As String = ddlYear.SelectedItem.Value

			If day.Length = 1 Then
				day = "0" + day
			End If
			If month.Length = 1 Then
				month = "0" + month
			End If
			txtDateOfBirth.Text = month + "/" + day + "/" + year
			args.IsValid = True
		End Sub
		Protected Sub rbMale_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)
			txtHiddenGender.Text = "1"
		End Sub

		Protected Sub rbFemale_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)
			txtHiddenGender.Text = "2"
		End Sub

		Protected Sub rbMen_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)
			txtHiddenToBeMatesWith.Text = "1"
		End Sub

		Protected Sub rbWomen_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)
			txtHiddenToBeMatesWith.Text = "2"
		End Sub

		Protected Sub rbMenAndWomen_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)
			txtHiddenToBeMatesWith.Text = "3"
		End Sub

		Private Sub cvReferrer_ServerValidate(ByVal source As Object, ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs)
			Dim referer As User = Users.GetUserByEmail(txtReferrer.Text)
			If referer <> Nothing Then
				args.IsValid = True
			Else
				args.IsValid = False
			End If
		End Sub

		Private Sub cvHtmlInFirstName_ServerValidate(ByVal source As Object, ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs)
			Dim fn As String = Request.Form(txtFirstName.UniqueID)

			If isHTML(fn) Then
				args.IsValid = False
			Else
				args.IsValid = True
			End If
		End Sub

		Private Sub cvHtmlInLastName_ServerValidate(ByVal source As Object, ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs)
			Dim ln As String = Request.Form(txtLastName.UniqueID)

			If isHTML(ln) Then
				args.IsValid = False
			Else
				args.IsValid = True
			End If
		End Sub

		Private Sub cvHtmlInCity_ServerValidate(ByVal source As Object, ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs)
			Dim city As String = Request.Form(txtCity.UniqueID)

			If isHTML(city) Then
				args.IsValid = False
			Else
				args.IsValid = True
			End If
		End Sub

		Private Sub cvHtmlInZip_ServerValidate(ByVal source As Object, ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs)
			Dim zip As String = Request.Form(txtZip.UniqueID)

			If isHTML(zip) Then
				args.IsValid = False
			Else
				args.IsValid = True
			End If
		End Sub

		Private Sub cvHtmlInPlaceOfBirth_ServerValidate(ByVal source As Object, ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs)
			Dim pob As String = Request.Form(txtPlaceOfBirth.UniqueID)

			If isHTML(pob) Then
				args.IsValid = False
			Else
				args.IsValid = True
			End If
		End Sub

		Private Sub InitUser(ByVal user As User)
			Dim temp As String = ""

			temp = removeScriptTags(Request.Params(txtFirstName.UniqueID).Trim())
			user.Name = temp.Substring(0, Math.Min(temp.Length, Constants.TEXT_FIELD_DEFAULT_MAX_CHARS))

			temp = removeScriptTags(Request.Params(txtLastName.UniqueID).Trim())
			user.LastName = temp.Substring(0, Math.Min(temp.Length, Constants.TEXT_FIELD_DEFAULT_MAX_CHARS))

			user.Gender = Convert.ToInt32(Request.Params(txtHiddenGender.UniqueID))

			user.BirthDay = Convert.ToDateTime(Request.Params(txtDateOfBirth.UniqueID))

			If Request.Params(chkFor1.UniqueID) = "on" Then
				user.MatesSR = True
			Else
				user.MatesSR = False
			End If
			If Request.Params(chkFor2.UniqueID) = "on" Then
				user.MatesPen = True
			Else
				user.MatesPen = False
			End If
			If Request.Params(chkFor3.UniqueID) = "on" Then
				user.MatesFriends = True
			Else
				user.MatesFriends = False
			End If
			If Request.Params(chkFor4.UniqueID) = "on" Then
				user.MatesDating = True
			Else
				user.MatesDating = False
			End If
			If Request.Params(chkFor5.UniqueID) = "on" Then
				user.MatesAP = True
			Else
				user.MatesAP = False
			End If
			If Request.Params(chkFor6.UniqueID) = "on" Then
				user.MatesJHO = True
			Else
				user.MatesJHO = False
			End If

			user.GenderPreference = Convert.ToInt32(Request.Params(txtHiddenToBeMatesWith.UniqueID))

			user.MaritalStatus = Convert.ToInt32(Request.Params(rbSDS.NamingContainer.UniqueID + ":" + rbSDS.GroupName))

			temp = removeScriptTags(Request.Params(txtAboutMe.UniqueID).Trim())
			user.AboutMe = temp.Substring(0, Math.Min(temp.Length, Constants.TEXT_AREA_ABOUT_ME_MAX_CHARS))

			temp = removeScriptTags(Request.Params(txtLookingFor.UniqueID).Trim())
			user.LookingFor = temp.Substring(0, Math.Min(temp.Length, Constants.TEXT_AREA_LOOKING_FOR_MAX_CHARS))

			If Convert.ToInt32(Request.Params(ddlCountry.UniqueID).Trim()) <> -1 Then
				user.CountryID = Convert.ToInt32(Request.Params(ddlCountry.UniqueID).Trim())
			End If

			temp = removeScriptTags(Request.Params(txtCity.UniqueID).Trim())
			user.City = temp.Substring(0, Math.Min(temp.Length, Constants.TEXT_FIELD_DEFAULT_MAX_CHARS))

			temp = removeScriptTags(Request.Params(txtZip.UniqueID).Trim())
			user.ZipCode = temp.Substring(0, Math.Min(temp.Length, Constants.TEXT_FIELD_ZIPCODE_CHARS))

			temp = removeScriptTags(Request.Params(txtInterests.UniqueID).Trim())
			user.Interests = temp.Substring(0, Math.Min(temp.Length, Constants.TEXT_AREA_LONG_MAX_CHARS))

			temp = removeScriptTags(Request.Params(txtOccupation.UniqueID).Trim())
			user.Occupation = temp.Substring(0, Math.Min(temp.Length, Constants.TEXT_AREA_OCCUPATION_MAX_CHARS))

			temp = removeScriptTags(Request.Params(txtPlaceOfBirth.UniqueID).Trim())
			user.PlaceOfBirth = temp.Substring(0, Math.Min(temp.Length, Constants.TEXT_FIELD_DEFAULT_MAX_CHARS))

			temp = removeScriptTags(Request.Params(txtAffiliations.UniqueID).Trim())
			user.Affiliations = temp.Substring(0, Math.Min(temp.Length, Constants.TEXT_AREA_AFFILIATIONS_MAX_CHARS))

			temp = removeScriptTags(Request.Params(txtCompanies.UniqueID).Trim())
			user.Companies = temp.Substring(0, Math.Min(temp.Length, Constants.TEXT_AREA_COMPANIES_MAX_CHARS))

			temp = removeScriptTags(Request.Params(txtSchools.UniqueID).Trim())
			user.Schools = temp.Substring(0, Math.Min(temp.Length, Constants.TEXT_AREA_SCHOOLS_MAX_CHARS))

			'
'			if(Request.Params[txtFavClipSongURL1.UniqueID].Trim() != Constants.ENTER_URL_INIT_VALUE)
'			{
'				temp = removeScriptTags(Request.Params[txtFavClipSongURL1.UniqueID].Trim());
'				user.SongURL1 = temp.Substring(0, Math.Min(temp.Length, Constants.TEXT_FIELD_URL_CHARS));
'			}
'			else
'				user.SongURL1 = "";
'			if(Request.Params[txtFavClipSongName1.UniqueID].Trim() != Constants.ENTER_URL_NAME_INIT_VALUE)
'			{
'				temp = removeScriptTags(Request.Params[txtFavClipSongName1.UniqueID].Trim());
'				user.SongURLName1 = temp.Substring(0, Math.Min(temp.Length, Constants.TEXT_FIELD_DEFAULT_MAX_CHARS));
'			}
'			else
'				user.SongURLName1 = "";
'
'			if(Request.Params[txtFavClipSongURL2.UniqueID].Trim() != Constants.ENTER_URL_INIT_VALUE)
'			{
'				temp = removeScriptTags(Request.Params[txtFavClipSongURL2.UniqueID].Trim());
'				user.SongURL2 = temp.Substring(0, Math.Min(temp.Length, Constants.TEXT_FIELD_URL_CHARS));
'			}
'			else
'				user.SongURL2 = "";
'
'			if(Request.Params[txtFavClipSongName2.UniqueID].Trim() != Constants.ENTER_URL_NAME_INIT_VALUE)
'			{
'				temp = removeScriptTags(Request.Params[txtFavClipSongName2.UniqueID].Trim());
'				user.SongURLName2 = temp.Substring(0, Math.Min(temp.Length, Constants.TEXT_FIELD_DEFAULT_MAX_CHARS));
'			}
'			else
'				user.SongURLName2 = "";
'
'			if(Request.Params[txtFavClipSongURL3.UniqueID].Trim() != Constants.ENTER_URL_INIT_VALUE)
'			{
'				temp = removeScriptTags(Request.Params[txtFavClipSongURL3.UniqueID].Trim());
'				user.SongURL3 = temp.Substring(0, Math.Min(temp.Length, Constants.TEXT_FIELD_URL_CHARS));
'			}
'			else
'				user.SongURL3 = "";
'			if(Request.Params[txtFavClipSongName3.UniqueID] != Constants.ENTER_URL_NAME_INIT_VALUE)
'			{
'				temp = removeScriptTags(Request.Params[txtFavClipSongName3.UniqueID].Trim());
'				user.SongURLName3 = temp.Substring(0, Math.Min(temp.Length, Constants.TEXT_FIELD_DEFAULT_MAX_CHARS));
'			}
'			else
'				user.SongURLName3 = "";
'			


			If Request.Params(txtFavImage.UniqueID).Trim() <> Constants.ENTER_URL_IMAGE_INIT_VALUE Then
				temp = removeScriptTags(Request.Params(txtFavImage.UniqueID).Trim())
				user.ImageURL = temp.Substring(0, Math.Min(temp.Length, Constants.TEXT_FIELD_URL_CHARS))
			Else
				user.ImageURL = ""
			End If

			If Request.Params(txtFavImageName.UniqueID).Trim() <> Constants.ENTER_URL_IMAGE_NAME_INIT_VALUE Then
				temp = removeScriptTags(Request.Params(txtFavImageName.UniqueID).Trim())
				user.ImageURLName = temp.Substring(0, Math.Min(temp.Length, Constants.TEXT_FIELD_URL_CHARS))
			Else
				user.ImageURLName = ""
			End If

			temp = removeScriptTags(Request.Params(txtFavMusic.UniqueID).Trim())
			user.Music = temp.Substring(0, Math.Min(temp.Length, Constants.TEXT_AREA_LONG_MAX_CHARS))

			temp = removeScriptTags(Request.Params(txtFavBooks.UniqueID).Trim())
			user.Books = temp.Substring(0, Math.Min(temp.Length, Constants.TEXT_AREA_LONG_MAX_CHARS))

			temp = removeScriptTags(Request.Params(txtFavTVShows.UniqueID).Trim())
			user.TV = temp.Substring(0, Math.Min(temp.Length, Constants.TEXT_AREA_LONG_MAX_CHARS))

			temp = removeScriptTags(Request.Params(txtFavMovies.UniqueID).Trim())
			user.Movies = temp.Substring(0, Math.Min(temp.Length, Constants.TEXT_AREA_LONG_MAX_CHARS))

			user.EditDate = DateTime.Now

			user.Save()
		End Sub
		Protected Sub btnSignMeUp_Click(ByVal sender As Object, ByVal e As System.EventArgs)
			If Page.IsValid Then
				InitUser(LoggedUser)
				Response.Redirect(Constants.USER_PROFILE + "?action=" + Constants.PROFILE_CHANGES_SUBMITTED)
			Else
				lblChangesSubmitted.Visible = False
			End If
		End Sub

		Private Sub cvZip_ServerValidate(ByVal source As Object, ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs)
			Dim countryID As Integer = Convert.ToInt32(Request.Params(ddlCountry.UniqueID))
			If (countryID = Countries.USAID OrElse countryID = Countries.CANADAID) AndAlso Request.Params(txtZip.UniqueID) = "" Then
				args.IsValid = False
			Else
				args.IsValid = True
			End If
		End Sub

		Protected Overloads Overrides Sub Render(ByVal writer As HtmlTextWriter)
			Dim stringBuilder As New StringBuilder()
			Dim stringWriter As New StringWriter(stringBuilder)
			Dim htmlWriter As New HtmlTextWriter(stringWriter)
			MyBase.Render(htmlWriter)
			Dim html As String = stringBuilder.ToString()
			Dim start As Integer = html.IndexOf("<form name=""") + 12
			Dim [end] As Integer = html.IndexOf("""", start)
			Dim formID As String = html.Substring(start, [end] - start)
			Dim replace As String = formID.Replace(":", "_")
			html = html.Replace("document." + formID, "document." + replace)
			writer.Write(html)
		End Sub

	End Class
End Namespace






